cmake_minimum_required(VERSION 3.10)

#set(CMAKE_CXX_STANDARD 14)

option(WITH_QT "qt" OFF)
option(WITH_TUYA "tuya iot" OFF)
option(WITH_LGVL "lgvl ui" OFF)
set(PLAT ${ARCH})

include_directories(${CMAKE_SOURCE_DIR}/common/utils)
include_directories(${CMAKE_SOURCE_DIR}/services/service_base)
include_directories(${CMAKE_SOURCE_DIR}/${LIBJPEGTURBO_ROOT}/include)
include_directories(${CMAKE_SOURCE_DIR}/${LIBYUV_ROOT}/include)
link_directories(${CMAKE_SOURCE_DIR}/${LIBJPEGTURBO_ROOT}/lib)
link_directories(${CMAKE_SOURCE_DIR}/${LIBPNG_ROOT}/lib)
link_directories(${CMAKE_SOURCE_DIR}/${ZLIB_ROOT}/lib)
link_directories(${CMAKE_SOURCE_DIR}/${LIBYUV_ROOT}/lib)

message("${CMAKE_SOURCE_DIR}/${LIBJPEGTURBO_ROOT}/include")

if (WITH_LGVL)
    message("lgvl: ${WITH_LGVL}")
    message("lgvl_root: ${LGVL_ROOT}")
    add_definitions(-D_WITH_LGVL)
    include_directories(${CMAKE_SOURCE_DIR}/${LGVL_ROOT}/include)
    link_directories(${CMAKE_SOURCE_DIR}/${LGVL_ROOT}/lib)
endif ()

message(STATUS "plat:${PLAT}")

if (WITH_TUYA)
    include_directories(${TUYA_PATH}/include)
    link_libraries(${TUYA_PATH}/lib)
    add_definitions(-DWITH_TUYA)
endif ()

if (${PLAT} STREQUAL "amd64")
    message(STATUS "amd64")
    add_definitions(-DNORMAL_PC)
    if (WITH_QT)
        include_directories(/usr/include/x86_64-linux-gnu/qt5)
        link_directories(/usr/lib/x86_64-linux-gnu/)
    endif ()
    set(OPENCV_PATH "/opt/data/libs/opencv-4.0.1/amd64/")
endif ()

if (${PLAT} STREQUAL "tina3")
    message(STATUS "tina3")
    if (WITH_QT)
        set(QT_PATH /usr/local/qt5-arm/)
        include_directories(${QT_PATH}/include)
        include_directories(/opt/data/benew/src/cutedevice/thirdparty/nttr1/include/)
        include_directories(/opt/data/libs/ffmpeg-4.1.3/nttr1/include)
        link_directories(${QT_PATH}/lib)
    endif ()
    link_directories(/opt/data/benew/src/cutedevice/thirdparty/nttr1/lib)
    set(OPENCV_PATH "/opt/data/libs/opencv-3.4.1/build_r311/install")
endif ()
if (${PLAT} STREQUAL "arm64")
    message(STATUS "arm64")
    include_directories(${SYSROOT_PATH}/usr/include/qt5)
    set(QT_PATH ${SYSROOT_PATH}/usr/lib/cmake)
endif ()

message(STATUS "QT path: ${QT_PATH}")

if (WITH_QT)
    message(STATUS "with qt")
    add_definitions(-D__OPENGL_QT)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTORCC ON)

    find_package(Qt5 REQUIRED
            Widgets
            )
    set(OPENGL_QT_LIBS
            Qt5::Widgets
            )

endif ()

if (WITH_OPENCV)
    message(STATUS "with opencv ${OPENCV_PATH}")
    add_definitions(-DWITH_OPENCV)
    include_directories(${OPENCV_PATH}/include/opencv4)
    link_directories(${OPENCV_PATH}/lib)
    set(OPENCV_FILES
            CameraCapture.cpp CameraCapture.h)
    set(OPENCV_LIBS
            opencv_imgproc
            opencv_imgcodecs
            opencv_video opencv_videoio
            opencv_core)
endif ()

include_directories(.)
include_directories(src)
include_directories(common)

set(BASE_FILES
        snakyrun.cpp
        )

set(COMMON_FILES
        ../../common/utils/cm_print.c
        ../../common/utils/cm_print.h
        ../../common/utils/cm_logprint.h
        )

if (WITH_QT)
    set(WINDOW_FILES
            src/CMBaseWidget.cpp
            src/CMBaseWidget.h
            src/CMCenterWidget.h
            src/CMCenterWidget.cpp
            src/CMTimeShowWidget.cpp
            src/CMTimeShowWidget.h
            )
endif ()

if (WITH_LGVL)
    set(UI_FILES
        CMUIShowInterface.cpp
        CMUIShowInterface.h
            CMUIShowWithLVGL.cpp
            CMUIShowWithLVGL.h
    )

    add_executable(cm_ui_show_test
        CMUIShowTest.cpp
            ${UI_FILES}
    )

    target_link_libraries(cm_ui_show_test
            lvgl_demos
            lvgl lvgl_thorvg
            servicebase
            jkfuncs
        utils
            turbojpeg jpeg png zlib
            pthread
    )
endif ()

add_library(service-ui
    ${UI_FILES}
)


